﻿using System;

using ApplicationBoilerplate.DataProvider;

using Raven.Client;
using Raven.Client.Document;

namespace MVCBootstrap.RavenDB {

	public class Session : ISession {
		private readonly IDocumentSession session;

		public Session(String connectionStringName) {
			IDocumentStore store = new DocumentStore { ConnectionStringName = connectionStringName };
			this.session = store.Initialize().OpenSession();
		}

		public IDocumentSession GetSession() {
			return this.session;
		}

		public IRepository<TEntity> GetRepository<TEntity>() where TEntity : class {
			return new Repository<TEntity>(this);
		}

		public void SaveChanges() {
			this.session.SaveChanges();
		}

		public void Dispose() {
			// TODO: !?!?!?!
			this.session.Dispose();
		}
	}
}